<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.type" placeholder="请输入配置类型" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查 询</el-button>
        <el-button type="primary" plain @click="addOrUpdateHandle()">新 增</el-button>
        <!-- <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      :max-height="tableHeight"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        min-width="180"
        label="配置类型">
      </el-table-column>
      <el-table-column
        prop="code"
        header-align="center"
        align="center"
        min-width="200"
        label="标识码">
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        min-width="160"
        label="显示名称">
      </el-table-column>
      <el-table-column
        prop="value"
        header-align="center"
        align="center"
        min-width="160"
        label="具体值">
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        min-width="120"
        align="center"
        label="描述">
      </el-table-column>
      <el-table-column
        prop="sort"
        header-align="center"
        align="center"
        min-width="60"
        label="排序">
      </el-table-column>
      <el-table-column
        prop="parentId"
        header-align="center"
        align="center"
        min-width="60"
        label="PID">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        min-width="80"
        label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="danger">禁用</el-tag>
          <el-tag v-else size="small">正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" style="color:#53b4ff;" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" style="color:#fc8e2d;" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100, 200]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './confInfo-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          type: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        tableHeight:0,
        heightis: 180,
        dataListLoading: false,
        // dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    created () {
      this.getDataList()
      this.tackHeight()

    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sys/confInfo/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'type': this.dataForm.type
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
            console.log(this.dataList)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      // selectionChangeHandle (val) {
      //   this.dataListSelections = val
      // },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      tackHeight(){
      this.heightis = 180
      this.adjustTableHeight()
      },
      adjustTableHeight(){
      this.$nextTick(() => {
          console.log(window.innerHeight);
          this.tableHeight = window.innerHeight - this.heightis;
            //后面的50：根据需求空出的高度，自行调整
          console.log(this.tableHeight);
        })
      },
      // 删除
      deleteHandle (id) {
          this.$http({
            url: this.$http.adornUrl('/sys/confInfo/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
      }
    }
  }
</script>
<style lang="scss" scoped>

.mod-config{
    padding: 15px;
}
</style>
